package vistas;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import clases.Alumno;
import clases.Profesor;
import clases.Seccion;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JDProfesor extends javax.swing.JDialog {
	private JPanel jPprofesor;
	private JLabel jLabelNombre;
	private JLabel jLabelApellido;
	private JTextField jTextNombre;
	private JTextField jTextApellido;
	private AbstractAction abstractAction1;
	private AbstractAction abstractAction2;
	private JButton jButtonSalir;
	private JButton jButtonRegistrar;
	private JTextField jTextTitulo;
	private JTextField jTextCedula;
	private JLabel jLabelTitulo;
	private JLabel jLabelcedula;
	private Seccion _seccion;
	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				JDProfesor inst = new JDProfesor(frame,new Seccion());
				inst.setVisible(true);
			}
		});
	}
	
	public JDProfesor(JFrame frame,Seccion secion) {
		super(frame);
		initGUI();
		_seccion = secion;
	}
	
	private void initGUI() {
		try {
			setTitle("Registro del Profesor");
			{
				jPprofesor = new JPanel();
				getContentPane().add(jPprofesor, BorderLayout.CENTER);
				jPprofesor.setLayout(null);
				{
					jLabelcedula = new JLabel();
					jPprofesor.add(jLabelcedula);
					jLabelcedula.setText("Cedula:");
					jLabelcedula.setBounds(26, 40, 79, 14);
				}
				{
					jLabelNombre = new JLabel();
					jPprofesor.add(jLabelNombre);
					jLabelNombre.setText("Nombre:");
					jLabelNombre.setBounds(26, 89, 79, 14);
				}
				{
					jLabelApellido = new JLabel();
					jPprofesor.add(jLabelApellido);
					jLabelApellido.setText("Apellido:");
					jLabelApellido.setBounds(26, 139, 79, 14);
				}
				{
					jLabelTitulo = new JLabel();
					jPprofesor.add(jLabelTitulo);
					jLabelTitulo.setText("Titulo:");
					jLabelTitulo.setBounds(26, 191, 70, 14);
				}
				{
					jTextCedula = new JTextField();
					jPprofesor.add(jTextCedula);
					jTextCedula.setBounds(108, 37, 94, 21);
				}
				{
					jTextNombre = new JTextField();
					jPprofesor.add(jTextNombre);
					jTextNombre.setBounds(108, 89, 94, 21);
				}
				{
					jTextApellido = new JTextField();
					jPprofesor.add(jTextApellido);
					jTextApellido.setBounds(108, 136, 94, 21);
				}
				{
					jTextTitulo = new JTextField();
					jPprofesor.add(jTextTitulo);
					jTextTitulo.setBounds(105, 188, 97, 21);
				}
				{
					jButtonRegistrar = new JButton();
					jPprofesor.add(jButtonRegistrar);
					jButtonRegistrar.setText("Registrar");
					jButtonRegistrar.setBounds(240, 68, 109, 28);
					jButtonRegistrar.setAction(getAbstractAction1());
				}
				{
					jButtonSalir = new JButton();
					jPprofesor.add(jButtonSalir);
					jButtonSalir.setText("Volver");
					jButtonSalir.setBounds(240, 133, 109, 28);
					jButtonSalir.setAction(getAbstractAction2());
					jButtonSalir.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButtonSalir.actionPerformed, event="+evt);
							//TODO add your code for jButtonSalir.actionPerformed
						//	System.exit(0);	
						}
					});
				}
			}
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private AbstractAction getAbstractAction1() {
		if(abstractAction1 == null) {
			abstractAction1 = new AbstractAction("Registrar", null) {
				public void actionPerformed(ActionEvent evt) {
					Vector<JTextField> Jtextos = new Vector<JTextField>();
					Jtextos.add(jTextCedula);
					Jtextos.add(jTextNombre);
					Jtextos.add(jTextApellido);
					Jtextos.add(jTextTitulo);
					for(JTextField text: Jtextos){
						if(text.getText().equals("")){
							JOptionPane.showMessageDialog(new JFrame(),"Debe llenar todos los campos","Registro del Profesor",JOptionPane.WARNING_MESSAGE);
							return;
						}
					}
					_seccion.asignarProfesor(new Profesor(jTextCedula.getText(),jTextNombre.getText(),jTextApellido.getText(),jTextTitulo.getText()));
					JOptionPane.showMessageDialog(new JFrame(),"Profesor asignado con exito","Registro del Profesor",JOptionPane.INFORMATION_MESSAGE);
					for(JTextField text: Jtextos){
						text.setText("");
					}
				}
			};
		}
		return abstractAction1;
	}
	
	private AbstractAction getAbstractAction2() {
		if(abstractAction2 == null) {
			abstractAction2 = new AbstractAction("Volver", null) {
				public void actionPerformed(ActionEvent evt) {
					dispose();
				}
			};
		}
		return abstractAction2;
	}

}
